package test.db.ibatis;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class BoardManager {

	public static SqlMapClient sqlMap = null;

	public static void main(String[] args){

		String resource = "test/db/ibatis/sqlMapConfig.xml";
		Reader reader = null;

		try{

			reader = Resources.getResourceAsReader(resource);
			sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
			reader.close();



			List result = sqlMap.queryForList("getAllBoardList");
			Iterator<HashMap> iter = result.iterator();
			Object obj[] = null;

			System.out.println("======================================\n");
			while(iter.hasNext()){

				HashMap data = iter.next();
				obj = data.keySet().toArray();


				for(int i = 0; i<obj.length; i++){

//					System.out.print((String)obj[i] + " " + data.get(obj[i]) + " ");
					System.out.print(data.get(obj[i]) + " ");

				}//for ended
				System.out.println();

			}//while ended
			System.out.println("\n======================================");


			System.out.println("End");


		}catch(IOException e){
			e.printStackTrace();
		}catch(SQLException se){
			se.printStackTrace();
		}

	}
}
